package model

import (
	"gorm.io/gorm"
	__ "videosS_rpc/basic/proto"
)

type Episode struct {
	gorm.Model
	EpisodeId  int    `gorm:"type:int;commit:剧集Id"`
	Title      string `gorm:"type:varchar(225);commit:视频标题"`
	Duration   string `gorm:"type:varchar(225);commit:视频时长"`
	UpdateTime string `gorm:"type:varchar(225);commit:更新时间"`
	VIPLogs    int    `gorm:"type:int;commit:1:有,2:无"`
	VideoId    int    `gorm:"type:int;commit:视频Id"`
	PlayTime   string `gorm:"type:varchar(225);commit:播放时长"`
	UserId     int    `gorm:"type:int;commit:用户Id"`
}

func (e *Episode) EpisodeDEl(DB *gorm.DB, id int) (err error) {
	err = DB.Model(&e).Where("id = ?", id).Delete(&e).Error
	return err
}

func (e *Episode) EpisodeList(DB *gorm.DB, size, page int) (list []*__.EpisodeLis, err error) {
	offset := (page - 1) * size
	err = DB.Model(&e).Offset(offset).Limit(size).Find(&list).Error
	return list, err
}

func (e *Episode) EpisodeAdd(DB *gorm.DB) error {
	var err error
	err = DB.Create(&e).Error
	return err
}

func (e *Episode) IsEpisodeUser(DB *gorm.DB, VIPLogs, UserId int) error {
	var err error
	err = DB.Model(&e).Where("v_ip_logs = ?", VIPLogs).
		Where("user_id = ?", UserId).First(&e).Error
	return err
}
